<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>公选课管理</title>
	<meta name="decorator" content="default"/>
	<link rel="stylesheet" href="${ctxStatic}/multiselect2side/css/jquery.multiselect2side.css" type="text/css" media="screen" />
	<script type="text/javascript" src="${ctxStatic}/multiselect2side/js/jquery.multiselect2side.js" ></script>
	<%@ include file="/WEB-INF/views/include/dialog.jsp"%>
	<script type="text/javascript">
		$(document).ready(function() {
			var studentIds = '${ddCommonCourse.extStudents}';
			var myarray = studentIds.split(",");
			for(var i in myarray){
				$("#"+myarray[i]).attr("selected",true);
			}//数据恢复
			
			$("#s2id_extStudents").remove();
			$("#inputForm").validate(
					{
						rules : {
							teacherId: {
								required : true
							},
							classroomId: {
								required : true
							},
							classesName: {
								required : true
							},
							classesIds: {
								required : true
							},
							course: {
								required : true
							},
							startTime: {
								required : true
							},
							endTime: {
								required : true
							}
							
						},
						messages : {
							teacherId: {
								required : "请选择"
							},
							classroomId: {
								required : "请选择"
							},
							classesName: {
								required : "请填写"
							},
							classesIds: {
								required : "请选择"
							},
							course: {
								required : "请填写"
							},
							startTime: {
								required : "请选择"
							},
							endTime: {
								required : "请选择"
							}
						},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#weeks_all").click(function() {
				if( $(this).attr("checked") != "checked"){
					$("input[name='weeks']").removeAttr("checked");
				}else{
					$("input[name='weeks']").attr("checked", $(this).attr("checked"));
				}
			});
			$("#class_all").click(function() {
				if( $(this).attr("checked") != "checked"){
					$("input[name='classesIds']").removeAttr("checked");
				}else{
					$("input[name='classesIds']").attr("checked", $(this).attr("checked"));
				}
			});
		});
	</script>
	
	<script type="text/javascript">
		$().ready(function() {
			 $('#extStudents').multiselect2side({
				optGroupSearch: "班级: ",
				selectedPosition: 'right',
				moveOptions: false,
				labelsx: '全部学生',
				labeldx: '被选学生',
				autoSort: true,
				autoSortAvailable: true,
				search: "<img src='${ctxStatic}/multiselect2side/img/search.gif' />"
			}); 
		}); 
	</script>
<style>
.ms2side__header{
	height: 35px;
}
select.small.valid{
	height: 30px;
	width:auto;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/dd/ddCommonCourse/">公选课列表</a></li>
		<li class="active"><a href="${ctx}/dd/ddCommonCourse/form?id=${ddCommonCourse.id}">公选课<shiro:hasPermission name="dd:ddCommonCourse:edit">${not empty ddCommonCourse.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="dd:ddCommonCourse:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="ddCommonCourse" action="${ctx}/dd/ddCommonCourse/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>教师：</label>
			<div class="controls">
				<form:select path="teacherId"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getTeacherNameList(schoolId)}"
						itemLabel="name" itemValue="id" htmlEscape="false" class="" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>教室：</label>
			<div class="controls">
				<form:select path="classroomId"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getClassRoomNameList(schoolId)}"
						itemLabel="name" itemValue="id" htmlEscape="false" class="" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>组合班名称：</label>
			<div class="controls">
			<c:if test="${not empty ddCommonCourse.classesId}">
				${fns:getClassesName(ddCommonCourse.classesId)}
			</c:if>
			<c:if test="${empty ddCommonCourse.classesId}">
				<form:input path="classesName" htmlEscape="false" maxlength="1000" class="input-xlarge "/>
			</c:if>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>班级：</label>
			<div class="controls">
				<form:input path="classesIds" htmlEscape="false" maxlength="1000" class="input-xlarge "/>
				<form:checkboxes path="classesIds" items="${fns:getClassesListBySchoolId(schoolId)}" itemLabel="classes"
								itemValue="id" htmlEscape="false"/>
				<input type="checkbox" name="class_all" id="class_all"/>全选/取消全选
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">学生：</label>
			<div class="controls" style="overflow-x:hidden;">
				<%-- <form:input path="extStudents" type="hidden"/> --%>
			<form:select path="extStudents" id="extStudents" multiple="multiple" size="10">
				<c:forEach items="${classStudentList}" var="classStudent">
					 <optgroup label="${classStudent.classesName}"> 
						<c:forEach items="${classStudent.students}" var="students">
							<option id="${students.id}" value="${students.id}">${students.name}</option>
						</c:forEach>
						</optgroup>  
					</c:forEach>
			</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>任课名称：</label>
			<div class="controls">
				<form:input path="course" htmlEscape="false" maxlength="50" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remark" htmlEscape="false" maxlength="2000" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>每周上课日：</label>
			<div class="controls">
				<form:checkboxes path="weeks" items="${fns:getDictList('weeks')}" itemLabel="label"
								itemValue="value" htmlEscape="false"/>
				<input type="checkbox" name="weeks_all" id="weeks_all"/>全选/取消全选
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>课程开始时间：</label>
			<div class="controls">
				<input name="startTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${ddCommonCourse.startTime}" pattern="HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b style="color: red; font-size: large">*</b>课程结束时间：</label>
			<div class="controls">
				<input name="endTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${ddCommonCourse.endTime}" pattern="HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="dd:ddCommonCourse:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>


</body>
</html>